package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.RolespawnMapper;
import com.xgame.server.db.model.Rolespawn;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class RolespawnCsTool {
    @Resource
    private RolespawnMapper rolespawnMapper;

    //插入玩家记录
    public Integer insertRoleSpawn(Game.RoleSpawnCS data) throws Exception {
        Integer result = new Integer(0);

        Rolespawn account = new Rolespawn();
        account.setAccount(data.getAccount());
        account.setPlayerId(data.getPlayerID());
        account.setMapId(data.getMapId());
        account.setX(data.getX());
        account.setY(data.getY());
        account.setZ(data.getZ());
        account.setLastMapId(data.getLastMapId());
        account.setLastMapPosx(data.getLastMapPosx());
        account.setLastMapPosy(data.getLastMapPosy());
        account.setLastMapPosz(data.getLastMapPosz());

        return rolespawnMapper.insert(account);
    }

    //更新玩家记录
    public Integer updateRoleSpawn(Game.RoleSpawnCS data) throws Exception {
        EntityWrapper<Rolespawn> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        Rolespawn account = new Rolespawn();
        account.setAccount(data.getAccount());
        account.setPlayerId(data.getPlayerID());
        account.setMapId(data.getMapId());
        account.setX(data.getX());
        account.setY(data.getY());
        account.setZ(data.getZ());
        account.setLastMapId(data.getLastMapId());
        account.setLastMapPosx(data.getLastMapPosx());
        account.setLastMapPosy(data.getLastMapPosy());
        account.setLastMapPosz(data.getLastMapPosz());

        return rolespawnMapper.update(account, userWrapper);
    }

    //删除记录
    public Integer deleteRoleSpawn(Game.RoleSpawnCS data) throws Exception {
        EntityWrapper<Rolespawn> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        return rolespawnMapper.delete(userWrapper);
    }

    //查询记录
    public List<Rolespawn> selectRoleSpawn(String account) throws Exception {
        EntityWrapper<Rolespawn> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return rolespawnMapper.selectList(userWrapper);
    }
}
